package com.atguigu.source;

import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.connector.file.src.FileSource;
import org.apache.flink.connector.file.src.reader.TextLineInputFormat;
import org.apache.flink.core.fs.Path;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author yhm
 * @create 2024-04-01 15:23
 */
public class Test02_File {
    public static void main(String[] args) throws Exception {
        // 1. 创建环境
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 8081);

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(1);

        // 2. 读取数据源
        FileSource<String> source =
                FileSource.forRecordStreamFormat(new TextLineInputFormat(),new Path("input/words.txt"))
                        .build();
        DataStreamSource<String> fileSource = env.fromSource(source, WatermarkStrategy.noWatermarks(), "file_source");

        // 3. 处理数据

        // 4. 输出
        fileSource.print();

        // 5. 执行环境
        env.execute();
    }
}
